import 'package:flutter/material.dart';
import 'JvtdEmptyView.dart';
import 'JvtdLoadMoreView.dart';

typedef RefreshCallback = Future<void> Function(int, int);
typedef LoadMoreCallback = Future<void> Function(int, int);

class RefreshConfig {
  final EmptyStatus emptyStatus;
  final BaseEmptyView emptyView;
  final RefreshCallback refreshCallback;

  RefreshConfig({
    @required this.emptyStatus,
    this.emptyView,
    @required this.refreshCallback,
  });
}

class LoadMoreConfig {
  final int loadNum;
  final int loadSize;
  final LoadMoreStatus loadMoreStatus;
  final BaseLoadMoreView loadMoreView;
  final LoadMoreCallback loadMoreCallback;

  LoadMoreConfig({
    this.loadNum = 1,
    this.loadSize = 10,
    @required this.loadMoreStatus,
    this.loadMoreView,
    @required this.loadMoreCallback,
  });
}

class RefreshLoadView extends StatefulWidget {
  final RefreshConfig refreshConfig;
  final LoadMoreConfig loadMoreConfig;
  final Widget child;

  const RefreshLoadView(
      {Key key, this.refreshConfig, this.loadMoreConfig, this.child})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _RefreshLoadViewState(
      refreshConfig: refreshConfig,
      loadMoreConfig: loadMoreConfig,
      child: child,
    );
  }
}

class _RefreshLoadViewState extends State<RefreshLoadView> {
  final RefreshConfig refreshConfig;
  final LoadMoreConfig loadMoreConfig;
  final Widget child;

  _RefreshLoadViewState({
    this.refreshConfig,
    this.loadMoreConfig,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      onRefresh:(){
        refreshConfig.refreshCallback(loadMoreConfig.loadNum,loadMoreConfig.loadSize);
      },
      child: child,
    );
  }
}
